__author__ = 'hl'
import wx
import gridWithCheckBoxOnly as grb
import tableWithCheckBoxOnly as tbl
import wx.grid

class GridUI(wx.Panel):
    def __init__(self,parent,id,datas,lblsValue,size=wx.DefaultSize):
        wx.Panel.__init__(self,parent,-1,size=size)
        self.SizeWithOutFirstCol=None
        self.CreateGrid(datas,lblsValue)
        self.ColIsReadOnlyWithOutFirstCol(True)


    def CreateGrid(self,datas,lblsValue):
        self.grid = grb.GridWithCheckBoxOnly(self,-1,self.GetSize())
        self.table = tbl.TableWithCheckBoxOnly(datas,lblsValue)
        self.grid.SetTable(self.table)
        self.grid.SetGridColsSize(self.GetColWidthWithOutFirst(self.table.numCol -1))
        box = wx.GridBagSizer(5,5)
        box.Add(self.grid,(0,1),(8,11),wx.EXPAND)
        box.Add((5,5),(8,0))
        self.SetSizer(box)
        box.SetSizeHints(self)
        box.Fit(self)

    def GetSelectedRowS(self):
        selectedRows = []
        for row in self.grid.selectedRows:
            selectedRows.append(self.table.datas[row])

        return selectedRows

    def AppendRows(self,datas):
        self.table.AppendRows(datas)

    def Update(self,datas):
        self.table.UpdateTable(datas)

    def GetColWidthWithOutFirst(self,numCol):
        if not self.SizeWithOutFirstCol:
            self.SizeWithOutFirstCol = (self.GetSize()[0] - 22) / (numCol)
        return self.SizeWithOutFirstCol

    def ColIsReadOnlyWithOutFirstCol(self,v=False):
        for col in range(self.table.NumberCols):
            if col:
                self.grid.IsReadOnly(row = 1,col = col)


